package com.ftg.learn.controller;

import com.ftg.learn.entity.Product;
import com.ftg.learn.service.IProductService;
import com.ftg.learn.util.PageEx;
import com.ftg.learn.util.R;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.swing.*;


/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author 布衣
 * @since 2025-07-22
 */
@RestController
@RequestMapping("/product")
@Slf4j
public class ProductController {

    @Resource
    private IProductService productService;

    @Value("${server.port}")
    String port;

    @GetMapping("/list")
    public R<String> list(
          @RequestParam(value = "name", required = false) String name,
           @RequestParam(value = "page") Integer page,
             @RequestParam(value = "size") Integer size
    ) {
        log.info("port:{} 在运行", port);
        return productService.list(name, page, size);
    }

    /**
     * 图片上传功能实现
     *
     * @param product 商品
     * @return
     */
    @PostMapping("/add")
    public R<Boolean> add(@RequestBody Product product) {
        return R.ok(productService.save(product));
    }

    @PutMapping("/update/{id}")
    public R<String> update(@PathVariable("id") Integer id, @RequestBody Product product) {
        return R.ok();
    }

    @DeleteMapping("/delete/{id}")
    public R<String> delete(@PathVariable("id") Integer id) {
        return R.ok();
    }


}
